# include <stdio.h>
int main ()
{
	int n,a,b,c,sum;
	scanf("%d",&n);
	while(n--)
	{
	scanf("%d%d%d",&a,&b,&c);
	sum=a*70+b*21+c*15;
	while(sum>105)
	{
		sum=sum-105;
	}
	printf("%d\n",sum);
	}
	return 0;

}
